<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <title>Vue示例</title>
</head>

<body>
<div id="app">
    {{message}}
    <my-component></my-component>
</div>
<script charset="utf-8" src="../js/vue.min.js" type="text/javascript"></script>
<script type="text/javascript">
    Vue.component('my-component', {
        template: '<button @click="handleDispatch">派发事件</button>',
        methods: {
            handleDispatch: function () {
                this.$dispatch('on-message', '来自内部组件的数据');
            }
        }
    });

    var app = new Vue({
        el: '#app',
        data: {
            message: ''
        },
        events: {
            'on-message': function (msg) {
                this.message = msg;
            }
        }
    })
</script>
</body>

</html>
